package com.ruoyi.violate.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.violate.domain.Gantt;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.violate.domain.TaskWork;
import com.ruoyi.violate.service.ITaskWorkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-05-17
 */
@RestController
@RequestMapping("/violate/work")
public class TaskWorkController extends BaseController
{
    @Autowired
    private ITaskWorkService taskWorkService;

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('violate:work:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskWork taskWork)
    {
        startPage();
        List<TaskWork> list = taskWorkService.selectTaskWorkList(taskWork);
        return getDataTable(list);
    }

    @GetMapping("/listGantt")
    public TableDataInfo listGantt()
    {
        //查询数据，将数据组成一个集合
        TaskWork taskWork = new TaskWork();
        List<TaskWork> TaskWorks = taskWorkService.selectTaskWorkList(taskWork);
        HashMap<String, Gantt> map = new HashMap<>();
        ArrayList<Gantt> GanttList = new ArrayList<>();
        for (TaskWork work : TaskWorks) {
            boolean sign = true ;
            for (Map.Entry<String,Gantt> entry : map.entrySet()){
                //有相同则添加，没有相同的
                if (entry.getKey().contains(work.getShopName())) {
                    sign = false ;
                    if (work.getTaskTime().equals("6.1")){
                        entry.getValue().setDate1(work) ;
                    }if (work.getTaskTime().equals("6.2")){
                        entry.getValue().setDate2(work) ;
                    }if (work.getTaskTime().equals("6.3")){
                        entry.getValue().setDate3(work); ;
                    }if (work.getTaskTime().equals("6.4")){
                        entry.getValue().setDate4(work); ;
                    }if (work.getTaskTime().equals("6.5")){
                        entry.getValue().setDate5(work); ;
                    }if (work.getTaskTime().equals("6.6")){
                        entry.getValue().setDate6(work); ;
                    }if (work.getTaskTime().equals("6.7")){
                        entry.getValue().setDate7(work); ;
                    }if (work.getTaskTime().equals("6.8")){
                        entry.getValue().setDate8(work); ;
                    }if (work.getTaskTime().equals("6.9")){
                        entry.getValue().setDate9(work); ;
                    }if (work.getTaskTime().equals("6.10")){
                        entry.getValue().setDate10(work); ;
                    }if (work.getTaskTime().equals("6.11")){
                        entry.getValue().setDate11(work); ;
                    }if (work.getTaskTime().equals("6.12")){
                        entry.getValue().setDate12(work); ;
                    }if (work.getTaskTime().equals("6.13")){
                        entry.getValue().setDate13(work); ;
                    }if (work.getTaskTime().equals("6.14")){
                        entry.getValue().setDate14(work); ;
                    }if (work.getTaskTime().equals("6.15")){
                        entry.getValue().setDate15(work); ;
                    }if (work.getTaskTime().equals("6.16")){
                        entry.getValue().setDate16(work); ;
                    }if (work.getTaskTime().equals("6.17")){
                        entry.getValue().setDate17(work); ;
                    }if (work.getTaskTime().equals("6.18")){
                        entry.getValue().setDate18(work); ;
                    }if (work.getTaskTime().equals("6.19")){
                        entry.getValue().setDate19(work); ;
                    }if (work.getTaskTime().equals("6.20")){
                        entry.getValue().setDate20(work); ;
                    }if (work.getTaskTime().equals("6.21")){
                        entry.getValue().setDate21(work); ;
                    }if (work.getTaskTime().equals("6.22")){
                        entry.getValue().setDate22(work); ;
                    }if (work.getTaskTime().equals("6.23")){
                        entry.getValue().setDate23(work); ;
                    }if (work.getTaskTime().equals("6.24")){
                        entry.getValue().setDate24(work); ;
                    }if (work.getTaskTime().equals("6.25")){
                        entry.getValue().setDate25(work); ;
                    }if (work.getTaskTime().equals("6.26")){
                        entry.getValue().setDate26(work); ;
                    }if (work.getTaskTime().equals("6.27")){
                        entry.getValue().setDate27(work); ;
                    }if (work.getTaskTime().equals("6.28")){
                        entry.getValue().setDate28(work); ;
                    }if (work.getTaskTime().equals("6.29")){
                        entry.getValue().setDate29(work); ;
                    }if (work.getTaskTime().equals("6.30")){
                        entry.getValue().setDate30(work); ;
                    }if (work.getTaskTime().equals("6.31")){
                        entry.getValue().setDate31(work); ;
                    }

                }
            }
            if (sign){
              Gantt gantt = new Gantt();
              gantt.setShopName(work.getShopName());
                if (work.getTaskTime().equals("6.1")){
                    gantt.setDate1(work) ;
                }if (work.getTaskTime().equals("6.2")){
                    gantt.setDate2(work) ;
                }if (work.getTaskTime().equals("6.3")){
                    gantt.setDate3(work); ;
                }if (work.getTaskTime().equals("6.4")){
                    gantt.setDate4(work); ;
                }if (work.getTaskTime().equals("6.5")){
                    gantt.setDate5(work); ;
                }if (work.getTaskTime().equals("6.6")){
                    gantt.setDate6(work); ;
                }if (work.getTaskTime().equals("6.7")){
                    gantt.setDate7(work); ;
                }if (work.getTaskTime().equals("6.8")){
                    gantt.setDate8(work); ;
                }if (work.getTaskTime().equals("6.9")){
                    gantt.setDate9(work); ;
                }if (work.getTaskTime().equals("6.10")){
                    gantt.setDate10(work); ;
                }if (work.getTaskTime().equals("6.11")){
                    gantt.setDate11(work); ;
                }if (work.getTaskTime().equals("6.12")){
                    gantt.setDate12(work); ;
                }if (work.getTaskTime().equals("6.13")){
                    gantt.setDate13(work); ;
                }if (work.getTaskTime().equals("6.14")){
                    gantt.setDate14(work); ;
                }if (work.getTaskTime().equals("6.15")){
                    gantt.setDate15(work); ;
                }if (work.getTaskTime().equals("6.16")){
                    gantt.setDate16(work); ;
                }if (work.getTaskTime().equals("6.17")){
                    gantt.setDate17(work); ;
                }if (work.getTaskTime().equals("6.18")){
                    gantt.setDate18(work); ;
                }if (work.getTaskTime().equals("6.19")){
                    gantt.setDate19(work); ;
                }if (work.getTaskTime().equals("6.20")){
                    gantt.setDate20(work); ;
                }if (work.getTaskTime().equals("6.21")){
                    gantt.setDate21(work); ;
                }if (work.getTaskTime().equals("6.22")){
                    gantt.setDate22(work); ;
                }if (work.getTaskTime().equals("6.23")){
                    gantt.setDate23(work); ;
                }if (work.getTaskTime().equals("6.24")){
                    gantt.setDate24(work); ;
                }if (work.getTaskTime().equals("6.25")){
                    gantt.setDate25(work); ;
                }if (work.getTaskTime().equals("6.26")){
                    gantt.setDate26(work); ;
                }if (work.getTaskTime().equals("6.27")){
                    gantt.setDate27(work); ;
                }if (work.getTaskTime().equals("6.28")){
                    gantt.setDate28(work); ;
                }if (work.getTaskTime().equals("6.29")){
                    gantt.setDate29(work); ;
                }if (work.getTaskTime().equals("6.30")){
                    gantt.setDate30(work); ;
                }if (work.getTaskTime().equals("6.31")){
                    gantt.setDate31(work); ;
                }
              map.put(work.getShopName(),gantt) ;
            }
        }

        for (Map.Entry<String,Gantt> entry : map.entrySet()){
            GanttList.add(entry.getValue()) ;
        }
        return getDataTable(GanttList);
    }

    @GetMapping("/newlistGantt")
    public TableDataInfo newlistGantt()
    {
        //查询数据，将数据组成一个集合
        TaskWork taskWork = new TaskWork();
        List<TaskWork> TaskWorks = taskWorkService.selectTaskWorkList(taskWork);
        HashMap<String, Gantt> map = new HashMap<>();
        ArrayList<Gantt> GanttList = new ArrayList<>();
        for (TaskWork work : TaskWorks) {
            boolean sign = true ;
            for (Map.Entry<String,Gantt> entry : map.entrySet()){
                //有相同则添加，没有相同的
                if (entry.getKey().contains(work.getShopName())) {
                    sign = false ;
                    entry.getValue().getDates().add(work) ;
                }
            }
            if (sign){
                Gantt gantt = new Gantt();
                gantt.setShopName(work.getShopName());
                ArrayList<TaskWork> taskWorks = new ArrayList<>();
                taskWorks.add(work) ;
                gantt.setDates(taskWorks);
                map.put(work.getShopName(),gantt) ;
            }
        }

        for (Map.Entry<String,Gantt> entry : map.entrySet()){
            GanttList.add(entry.getValue()) ;
        }
        return getDataTable(GanttList);
    }




    @GetMapping("/one")
    public AjaxResult listOne(TaskWork taskWork)
    {
        List<TaskWork> taskWorks = taskWorkService.selectTaskWorkList(taskWork);
        TaskWork task = new TaskWork();
        if (taskWorks.size() == 0){
            return success(task);
        }
        task = taskWorks.get(0) ;
        return success(task);
    }

    /**
     * 导出【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('violate:work:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskWork taskWork)
    {
        List<TaskWork> list = taskWorkService.selectTaskWorkList(taskWork);
        ExcelUtil<TaskWork> util = new ExcelUtil<TaskWork>(TaskWork.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('violate:work:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(taskWorkService.selectTaskWorkById(id));
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('violate:work:queryOne')")
    @PostMapping("/one")
    public AjaxResult getInfoOne(@RequestBody TaskWork taskWork)
    {
        List<TaskWork> taskWorks = taskWorkService.selectTaskWorkList(taskWork);
        if (taskWorks.size() == 0){
            //如果获取到空,生成一个数据
            taskWorkService.insertTaskWork(taskWork);
        }
        taskWorks = taskWorkService.selectTaskWorkList(taskWork);
        return success(taskWorks.get(0));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('violate:work:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskWork taskWork)
    {
        return toAjax(taskWorkService.insertTaskWork(taskWork));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('violate:work:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskWork taskWork)
    {

        return toAjax(taskWorkService.updateTaskWork(taskWork));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('violate:work:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(taskWorkService.deleteTaskWorkByIds(ids));
    }



}
